package nancal.mp.entity.dev

import nancal.mp.entity.base.TestBase
import nbcp.base.extend.resolvePath
import nbcp.base.utils.FileUtil
import nbcp.myoql.code.generator.db.es.EsMappingGenerator
import nbcp.myoql.code.generator.db.es.EsrGenerator4Kotlin
import org.junit.jupiter.api.Test
import java.io.File


class EsTool : TestBase() {
    @Test
    fun gen_es() {

        var list = EsMappingGenerator().generateMapping(
            "${entityPkgName}.db.es."
        )


        list.forEach {
            var path = File(workPath).resolvePath(
                "../${ormProjectName}/src/main/kotlin/${ormPkgPath}/db/es/mapping",
                it.code
            )

            writeToFile(path, it.value)
        }


        var entities = EsrGenerator4Kotlin().generateEntity(
            "${entityPkgName}.db.es.",
            "${entityPkgName}.db.es.table"
        )

        var targetEntityPathName = FileUtil.resolvePath(
            File(workPath).parentFile.path + "/${ormProjectName}/src/main/kotlin",
            "${ormPkgName}.db.es.table.".split(".").joinToString("/")
        )
        File(targetEntityPathName).deleteRecursively();
        File(targetEntityPathName).mkdirs()

        entities.forEach {
            writeToFile(FileUtil.resolvePath(targetEntityPathName, it.code), it.value);
        }
    }


}
